package com.whfc.common.auth;

import java.util.Date;
import java.util.Map;

/**
 * jwt负载
 *
 * @author xuguocheng
 * @date 2021-05-05
 */
public class JwtPayLoad {

    /**
     * jwt默认过期时间:2小时
     */
    public static final int DEFAULT_TOKEN_EXPIRES_IN = 2 * 60 * 60 * 1000;

    /**
     * 应用类型
     */
    private String appType;

    /**
     * 登录方式
     */
    private String loginMethod;

    /**
     * 用户标识(登陆名)
     */
    private String user;

    /**
     * 版本号
     */
    private Long ver;

    /**
     * 过期时间
     */
    private Date expireAt;

    /**
     * 扩展信息
     */
    private Map<String, Object> attrs;

    public JwtPayLoad() {
        this.expireAt = new Date(System.currentTimeMillis() + DEFAULT_TOKEN_EXPIRES_IN);
    }

    public JwtPayLoad(String appType, String loginMethod, String user) {
        this.appType = appType;
        this.loginMethod = loginMethod;
        this.user = user;
        this.expireAt = new Date(System.currentTimeMillis() + DEFAULT_TOKEN_EXPIRES_IN);
    }

    public JwtPayLoad(String appType, String loginMethod, String user, Long ver) {
        this.appType = appType;
        this.loginMethod = loginMethod;
        this.user = user;
        this.ver = ver;
        this.expireAt = new Date(System.currentTimeMillis() + DEFAULT_TOKEN_EXPIRES_IN);
    }

    public JwtPayLoad(String appType, String loginMethod, String user, Long ver, Date expireAt) {
        this.appType = appType;
        this.loginMethod = loginMethod;
        this.user = user;
        this.ver = ver;
        this.expireAt = expireAt;
    }

    public JwtPayLoad(String appType, String loginMethod, String user, Long ver, Date expireAt, Map<String, Object> attrs) {
        this.appType = appType;
        this.loginMethod = loginMethod;
        this.user = user;
        this.ver = ver;
        this.expireAt = expireAt;
        this.attrs = attrs;
    }

    public String getAppType() {
        return appType;
    }

    public void setAppType(String appType) {
        this.appType = appType;
    }

    public String getLoginMethod() {
        return loginMethod;
    }

    public void setLoginMethod(String loginMethod) {
        this.loginMethod = loginMethod;
    }

    public String getUser() {
        return user;
    }

    public void setUser(String user) {
        this.user = user;
    }

    public Long getVer() {
        return ver;
    }

    public void setVer(Long ver) {
        this.ver = ver;
    }

    public Date getExpireAt() {
        return expireAt;
    }

    public void setExpireAt(Date expireAt) {
        this.expireAt = expireAt;
    }

    public Map<String, Object> getAttrs() {
        return attrs;
    }

    public void setAttrs(Map<String, Object> attrs) {
        this.attrs = attrs;
    }

    @Override
    public String toString() {
        return "JwtPayLoad{" +
                "appType='" + appType + '\'' +
                ", loginMethod='" + loginMethod + '\'' +
                ", user='" + user + '\'' +
                ", ver=" + ver +
                ", expireAt=" + expireAt +
                ", attrs=" + attrs +
                '}';
    }
}
